<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['diy']=$this->plugin_setting('diy');
if($_RQ['op']=='main'){
	exi($return);
}
$return['ispay']=array('0'=>'未支付','1'=>'已支付');
/*******op*******/
set_html('title','服务订单');
//paisong_type,指定师傅的类型（0所有，1平台，2商户自己的员工）
if($_RQ['op']=='list'){
	$worker = pdo_get('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0);
	if(!$worker['type']){
		$params['sendtype']=1;
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}else{
		$return['status']=0;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_wxshifu_order',$params,array($pindex,$psize),$total,array(),'','createtime desc');
	if($list){
		foreach($list as &$item){
			$item['orderinfo']=$this->model('model')->getorder($item,1);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	$return['list']=$list;
	$return['isopenvoice']=$this->session('isopenvoice')?1:0;
	exi($return);
}

//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择','error');
	}
	$order=pdo_get('jy_wxshifu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$order['orderinfo']=$this->model('model')->getorder($order,1);
	$order['createtime']=date('Y-m-d H:i:s',$order['createtime']);
	$return['order']=$order;
	exi($return);
}
//员工确认订单
if($_RQ['op']=='getorder'){
	$order_id=intval($_RQ['id']);
	if(!$order_id){
		exi('订单不存在，请重新选择订单','error');
	}
	$worker = pdo_get('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
	$params=array('order_id'=>$order_id,'shifu_id'=>$worker['id']);
	$this->model('order')->order_get($params);
	exi('接收服务任务成功!','','/worker_order/');
}
//员工取消订单
if($_RQ['op']=='unreceive'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_update('jy_wxshifu_order',array('status'=>'1'),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('取消订单成功');
}